<template>
  <div>
    <h1>人员列表</h1>
    <input type="text" placeholder="请输入名称" v-model="name">
    <h2>第一个人的名字是{{fristName}}</h2>
    <button @click="add">添加</button>
    <button @click="addli">添加一个姓李的人</button>
    <button @click="addserve">向服务器请求添加信息</button>
    <ul>
        <li v-for="p in personList" :key="p.id">{{p.name}}</li>
    </ul>
    <h2>Count组件的求和为{{sum}}</h2>
  </div>
</template>

<script>
import {nanoid} from 'nanoid'
export default {
  name:'person',
  data() {
    return {
        name:''
    }
  },
  computed:{
    personList(){
        return  this.$store.state.personAbout.personList
    },
    sum(){
        return this.$store.state.countAbout.num
    },
    fristName(){
      return this.$store.getters['personAbout/fristname']
    }
  },
  methods:{
    add(){
        const person = {id:nanoid(),name:this.name}
        console.log(person)
        this.$store.commit('personAbout/ADD_PERSON',person)
        this.name=''
        // this.$store.dispatch('add',)
    },
    addli(){
      const person = {id:nanoid(),name:this.name}
      this.$store.dispatch('personAbout/addpersonLi',person)
      this.name=''
    },
    addserve(){
      this.$store.dispatch('personAbout/addpersonServe')
    }
  }
}
</script>

<style>

</style>